﻿using RealTimeCharts.LineChart;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RemoteData.model.wave
{
    public class WaveLenDisplaySetting
    {
        public int nMaxGratting;//最大光栅数量
        public int nGratting; //光栅数量

        public int nMaxChannel;//最大通道数
        public int nChannel; //通道数量（暂时未用到）

        public int maxTblFrequency;//表格最大刷新频率
        public int tblFrequency;//波长显示table的刷新频率

        public int maxChartFrequency;//图像最大刷新频率
        public int chartFrequency;//图像的刷新频率

        public int minDataCounts;//最小点数
        public int maxDataCounts;//最大点数
        public int dataCounts;//点数
        public List<double> referenceLines = new List<double>(); //参考线

        //波长的波动上限阙值
        public double upWaveLenThreshold;

        //波长的波动下限阙值
        public double lowWaveLenThreshold;

        //背景颜色
        public string warnBackColor;

        //文字颜色
        public string warnTextColor;

        //X轴自动调整
        public bool autoFitX;

        //X轴显示范围
        public ValueRange valueRangeX;

        //Y轴自动调整
        public bool autoFitY;

        //Y轴显示范围
        public ValueRange valueRangeY;

        public WaveLenDisplaySetting()
        {
            Reset();
        }

        public void Copy(WaveLenDisplaySettingViewModel setting)
        {
            this.nGratting = setting.nGratting;
            this.nMaxGratting = setting.nMaxGratting;

            this.nChannel = setting.nChannel;
            this.nMaxChannel = setting.nMaxChannel;

            this.tblFrequency = setting.tblFrequency;
            this.maxTblFrequency = setting.maxTblFrequency;

            this.chartFrequency = setting.chartFrequency;
            this.maxChartFrequency = setting.maxChartFrequency;

            this.minDataCounts = setting.minDataCounts;
            this.maxDataCounts = setting.maxDataCounts;
            this.dataCounts = setting.dataCounts;

            referenceLines = new List<double>();
            foreach (var v in setting.referenceLines)
            {
                referenceLines.Add(v);
            }

            this.upWaveLenThreshold = setting.upWaveLenThreshold;
            this.lowWaveLenThreshold = setting.lowWaveLenThreshold;
            this.warnBackColor = setting.warnBackColor;
            this.warnTextColor = setting.warnTextColor;

            this.autoFitX = setting.autoFitX;
            this.autoFitY = setting.autoFitY;
            this.valueRangeX = new ValueRange();
            this.valueRangeX.minValue = setting.valueRangeX.minValue;
            this.valueRangeX.maxValue = setting.valueRangeX.maxValue;
            this.valueRangeY = new ValueRange();
            this.valueRangeY.minValue = setting.valueRangeY.minValue;
            this.valueRangeY.maxValue = setting.valueRangeY.maxValue;
        }

        public void Copy(WaveLenDisplaySetting setting)
        {
            this.nGratting = setting.nGratting;
            this.nMaxGratting = setting.nMaxGratting;

            this.nChannel = setting.nChannel;
            this.nMaxChannel = setting.nMaxChannel;

            this.tblFrequency = setting.tblFrequency;
            this.maxTblFrequency = setting.maxTblFrequency;

            this.chartFrequency = setting.chartFrequency;
            this.maxChartFrequency = setting.maxChartFrequency;

            this.minDataCounts = setting.minDataCounts;
            this.maxDataCounts = setting.maxDataCounts;
            this.dataCounts = setting.dataCounts;

            referenceLines = new List<double>();
            foreach (var v in setting.referenceLines)
            {
                referenceLines.Add(v);
            }
            this.upWaveLenThreshold = setting.upWaveLenThreshold;
            this.lowWaveLenThreshold = setting.lowWaveLenThreshold;
            this.warnBackColor = setting.warnBackColor;
            this.warnTextColor = setting.warnTextColor;

            this.autoFitX = setting.autoFitX;
            this.autoFitY = setting.autoFitY;
            this.valueRangeX = new ValueRange(setting.valueRangeX);
            this.valueRangeY = new ValueRange(setting.valueRangeY);
        }

        public WaveLenDisplaySetting(WaveLenDisplaySettingViewModel setting)
        {
            Copy(setting);
        }

        public WaveLenDisplaySetting(WaveLenDisplaySetting setting)
        {
            Copy(setting);
        }

        public WaveLenDisplaySetting Clone()
        {
            return new WaveLenDisplaySetting(this);
        }

        public void Reset()
        {
            nMaxGratting = 100;
            nGratting = 30;

            nMaxChannel = 16;
            nChannel = 16;

            maxTblFrequency = 20;
            tblFrequency = 2;

            maxChartFrequency = 10;
            chartFrequency = 2;

            minDataCounts = 100;
            maxDataCounts = 10000;
            dataCounts = 1000;

            upWaveLenThreshold = 0.3;
            lowWaveLenThreshold = 0.3;
            warnBackColor = "#8B008B";
            warnTextColor = "#FFFFFF";

            referenceLines = new List<double>();

            autoFitX = true;
            autoFitY = true;

            valueRangeX = new ValueRange();
            valueRangeX.minValue = 0;
            valueRangeX.maxValue = valueRangeX.minValue + dataCounts;

            valueRangeY = new ValueRange();
            valueRangeY.minValue = 1510;
            valueRangeY.maxValue = 1590;
        }

    }
}
